bitkeeper revision 1.1236.1.181 (424d132aYORx7PllUl-nlTBMndGn4g)
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Fri, 1 Apr 2005 09:23:54 +0000 (09:23 +0000)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Fri, 1 Apr 2005 09:23:54 +0000 (09:23 +0000)
Improved lazy state switching -- flush the state switch through on the
first flush IPI received. This avoids needing to receive any further
ones at little cost (needed to flush TLB anyway). The main extra cost
will be that, when switching back to a guest, we won't save the
ctxt switch. But we may have saved an unbounded number of IPI flushes.
Signed-off-by: Keir Fraser <keir@xensource.com>
xen/arch/ia64/xenmisc.c
xen/arch/x86/domain.c
xen/arch/x86/mm.c
xen/arch/x86/smp.c
xen/include/xen/sched.h
xen/include/xen/smp.h

index 2e4b4366585ebb8101d0b7cfc3c2fe1fcc05d76b..ced4fc42865271ea7e1efc1168d43396ec011108 100644 (file)
@@ -53,7 +53,6 @@ platform_is_hp_ski(void)
 }
 
 /* calls in xen/common code that are unused on ia64 */
-void synchronise_execution_state(unsigned long cpu_mask) { }
 
 int grant_table_create(struct domain *d) { return 0; }
 void grant_table_destroy(struct domain *d)
index a53f4c09fb77edff231cafa4156c135e537b9939..d2b04ac8abbe05f2fc1d77535a0b361e9d417532 100644 (file)
@@ -744,12 +744,21 @@ long do_switch_to_user(void)
     return stu.rax; 
 }
 
+#define switch_kernel_stack(_n,_c) ((void)0)
+
 #elif defined(__i386__)
 
 #define load_segments(_p, _n) ((void)0)
 #define save_segments(_p)     ((void)0)
 #define clear_segments()      ((void)0)
 
+static inline void switch_kernel_stack(struct exec_domain *n, unsigned int cpu)
+{
+    struct tss_struct *tss = &init_tss[cpu];
+    tss->esp1 = n->arch.kernel_sp;
+    tss->ss1  = n->arch.kernel_ss;
+}
+
 #endif
 
 #define loaddebug(_ed,_reg) \
@@ -772,41 +781,35 @@ static void __context_switch(void)
         save_segments(p);
     }
 
-    memcpy(stack_ec,
-           &n->arch.user_ctxt,
-           sizeof(*stack_ec));
-
-    /* Maybe switch the debug registers. */
-    if ( unlikely(n->arch.debugreg[7]) )
+    if ( !is_idle_task(n->domain) )
     {
-        loaddebug(&n->arch, 0);
-        loaddebug(&n->arch, 1);
-        loaddebug(&n->arch, 2);
-        loaddebug(&n->arch, 3);
-        /* no 4 and 5 */
-        loaddebug(&n->arch, 6);
-        loaddebug(&n->arch, 7);
-    }
+        memcpy(stack_ec,
+               &n->arch.user_ctxt,
+               sizeof(*stack_ec));
 
-    if ( !VMX_DOMAIN(n) )
-    {
-        SET_FAST_TRAP(&n->arch);
+        /* Maybe switch the debug registers. */
+        if ( unlikely(n->arch.debugreg[7]) )
+        {
+            loaddebug(&n->arch, 0);
+            loaddebug(&n->arch, 1);
+            loaddebug(&n->arch, 2);
+            loaddebug(&n->arch, 3);
+            /* no 4 and 5 */
+            loaddebug(&n->arch, 6);
+            loaddebug(&n->arch, 7);
+        }
 
-#ifdef __i386__
+        if ( !VMX_DOMAIN(n) )
         {
-            /* Switch the kernel ring-1 stack. */
-            struct tss_struct *tss = &init_tss[cpu];
-            tss->esp1 = n->arch.kernel_sp;
-            tss->ss1  = n->arch.kernel_ss;
+            SET_FAST_TRAP(&n->arch);
+            switch_kernel_stack(n, cpu);
         }
-#endif
     }
 
     set_bit(cpu, &n->domain->cpuset);
     write_ptbase(n);
-    clear_bit(cpu, &p->domain->cpuset);
-
     __asm__ __volatile__ ( "lgdt %0" : "=m" (*n->arch.gdt) );
+    clear_bit(cpu, &p->domain->cpuset);
 
     percpu_ctxt[cpu].curr_ed = n;
 }
@@ -820,7 +823,7 @@ void context_switch(struct exec_domain *prev, struct exec_domain *next)
 
     set_current(next);
 
-    if ( ((realprev = percpu_ctxt[smp_processor_id()]. curr_ed) == next) || 
+    if ( ((realprev = percpu_ctxt[smp_processor_id()].curr_ed) == next) || 
          is_idle_task(next->domain) )
     {
         local_irq_enable();
@@ -851,18 +854,14 @@ void context_switch(struct exec_domain *prev, struct exec_domain *next)
     BUG();
 }
 
-static void __synchronise_lazy_execstate(void *unused)
-{
-    if ( percpu_ctxt[smp_processor_id()].curr_ed != current )
-    {
-        __context_switch();
-        load_LDT(current);
-        clear_segments();
-    }
-}
-void synchronise_lazy_execstate(unsigned long cpuset)
+int __sync_lazy_execstate(void)
 {
-    smp_subset_call_function(__synchronise_lazy_execstate, NULL, 1, cpuset);
+    if ( percpu_ctxt[smp_processor_id()].curr_ed == current )
+        return 0;
+    __context_switch();
+    load_LDT(current);
+    clear_segments();
+    return 1;
 }
 
 unsigned long __hypercall_create_continuation(
index a5648e68d5a22a7ea187ecb840513f39a4b5573e..b67458f521007e2591a67c2eaf62a46b2bcd5c6f 100644 (file)
@@ -2827,7 +2827,8 @@ void audit_domain(struct domain *d)
 
     if ( d != current->domain )
         domain_pause(d);
-    synchronise_lazy_execstate(~0UL);
+
+    sync_lazy_execstate_all();
 
     printk("pt base=%lx sh_info=%x\n",
            pagetable_val(d->exec_domain[0]->arch.guest_table)>>PAGE_SHIFT,
index 023b8fcab58601c8b9735b42e4ae457e121ee1b7..32641165a54f5ab8cdce0ea6c5adb338dd123df6 100644 (file)
@@ -154,10 +154,13 @@ asmlinkage void smp_invalidate_interrupt(void)
 {
     ack_APIC_irq();
     perfc_incrc(ipis);
-    if ( flush_va == FLUSHVA_ALL )
-        local_flush_tlb();
-    else
-        local_flush_tlb_one(flush_va);
+    if ( !__sync_lazy_execstate() )
+    {
+        if ( flush_va == FLUSHVA_ALL )
+            local_flush_tlb();
+        else
+            local_flush_tlb_one(flush_va);
+    }
     clear_bit(smp_processor_id(), &flush_cpumask);
 }
 
@@ -278,45 +281,6 @@ int smp_call_function(
     return 0;
 }
 
-/* Run a function on a subset of CPUs (may include local CPU). */
-int smp_subset_call_function(
-    void (*func) (void *info), void *info, int wait, unsigned long cpuset)
-{
-    struct call_data_struct data;
-
-    ASSERT(local_irq_is_enabled());
-
-    if ( cpuset & (1UL << smp_processor_id()) )
-    {
-        local_irq_disable();
-        (*func)(info);
-        local_irq_enable();
-    }
-
-    cpuset &= ((1UL << smp_num_cpus) - 1) & ~(1UL << smp_processor_id());
-    if ( cpuset == 0 )
-        return 0;
-
-    data.func = func;
-    data.info = info;
-    data.started = data.finished = 0;
-    data.wait = wait;
-
-    spin_lock(&call_lock);
-
-    call_data = &data;
-    wmb();
-
-    send_IPI_mask(cpuset, CALL_FUNCTION_VECTOR);
-
-    while ( (wait ? data.finished : data.started) != cpuset )
-        cpu_relax();
-
-    spin_unlock(&call_lock);
-
-    return 0;
-}
-
 static void stop_this_cpu (void *dummy)
 {
     clear_bit(smp_processor_id(), &cpu_online_map);
index c0567d8f28d3eb6192d8a7ec8cbf77214bf1ad48..2c9336bc91a8aac85464e80ca47b6e1cff18c624 100644 (file)
@@ -255,7 +255,9 @@ void domain_sleep(struct exec_domain *d);
  * Force loading of currently-executing domain state on the specified set
  * of CPUs. This is used to counteract lazy state switching where required.
  */
-void synchronise_lazy_execstate(unsigned long cpuset);
+#define sync_lazy_execstate_cpuset(_cpuset) flush_tlb_mask(_cpuset)
+#define sync_lazy_execstate_all()           flush_tlb_all()
+extern int __sync_lazy_execstate(void);
 
 extern void context_switch(
     struct exec_domain *prev, 
@@ -337,7 +339,7 @@ static inline void exec_domain_pause(struct exec_domain *ed)
     ASSERT(ed != current);
     atomic_inc(&ed->pausecnt);
     domain_sleep(ed);
-    synchronise_lazy_execstate(ed->domain->cpuset & (1UL << ed->processor));
+    sync_lazy_execstate_cpuset(ed->domain->cpuset & (1UL << ed->processor));
 }
 
 static inline void domain_pause(struct domain *d)
@@ -351,7 +353,7 @@ static inline void domain_pause(struct domain *d)
         domain_sleep(ed);
     }
 
-    synchronise_lazy_execstate(d->cpuset);
+    sync_lazy_execstate_cpuset(d->cpuset);
 }
 
 static inline void exec_domain_unpause(struct exec_domain *ed)
@@ -386,7 +388,7 @@ static inline void domain_pause_by_systemcontroller(struct domain *d)
             domain_sleep(ed);
     }
 
-    synchronise_lazy_execstate(d->cpuset);
+    sync_lazy_execstate_cpuset(d->cpuset);
 }
 
 static inline void domain_unpause_by_systemcontroller(struct domain *d)
index f3f08127b6410e985cbea5c555e0b637412ddbef..df80e23295141211c26a8a2e5993157ac4773291 100644 (file)
@@ -45,8 +45,6 @@ extern void smp_commence(void);
  */
 extern int smp_call_function(
     void (*func) (void *info), void *info, int retry, int wait);
-extern int smp_subset_call_function(
-    void (*func) (void *info), void *info, int wait, unsigned long cpuset);
 
 /*
  * True once the per process idle is forked
@@ -87,7 +85,6 @@ extern volatile int smp_msg_id;
 #define cpu_logical_map(cpu)                   0
 #define cpu_number_map(cpu)                    0
 #define smp_call_function(func,info,retry,wait)        0
-#define smp_subset_call_function(f,i,w,c)      ({ if ( (c&1) ) (*f)(i); 0; })
 #define cpu_online_map                         1
 
 #endif